package com.noranyunxi.www.util;

import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;

import java.net.URL;

public class SeleniumUtil {
    public static ChromeDriver initChromeDriver(String url) throws Exception {
        // 设置chromedriver路径
        System.setProperty("webdriver.chrome.driver", "/envConfig/chromedriver");

        //创建一个参数对象，用来控制chrome以无界面模式打开
        ChromeOptions options = new ChromeOptions();
        options.addArguments("--headless");
        options.addArguments("--disable-gpu");
        options.addArguments("--no-sandbox");
        ChromeDriver driver = new ChromeDriver(options);
        driver.get(url);
//        String pageSource = driver.getPageSource();
        return driver;
    }

    public static void quitChromeDriver(ChromeDriver driver) {
        if (driver != null) {
            driver.quit();
        }
    }
}
